package org.qqcui.designpattern.patterns.factory.abstractfactory.order;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.qqcui.designpattern.patterns.factory.abstractfactory.factory.PizzaFactory;
import org.qqcui.designpattern.patterns.factory.abstractfactory.pizza.Pizza;

/**
 * 订购披萨类
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2020-10-17 22:43
 **/
public class OrderPizza {

	private PizzaFactory factory;

	public OrderPizza(PizzaFactory factory) {
		setFactory(factory);
	}

	private void setFactory(PizzaFactory factory) {
		Pizza pizza = null;
		String orderType = null;
		do {
			orderType = getType();
			pizza = factory.createPizza(orderType);
			if (pizza == null) {
				System.out.println("未找到需要订购的披萨类型");
				break;
			}
			pizza.prepare();
			pizza.bake();
			pizza.cut();
			pizza.box();
		} while (true);
	}

	public String getType() {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("请输入订购披萨类型：");
		try {
			return bufferedReader.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
